package service;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import util.RegexUtil;

import dao.CommentDAO;
import dao.UserDAO;
import domain.Actor;
import domain.Comment;
import ex.DatabaseException;
import ex.ProjectCompositionFailedException;
import ex.RegistrationFailedException;

public class CommentService {

	CommentDAO commentDao = new CommentDAO();
	UserDAO userDao = new UserDAO();

	public LinkedList<Comment> getCommentsByMid(long mid)
			throws DatabaseException {
		return commentDao.selectCommentsByMid(mid);
	}

	public LinkedList<Comment> getCommentsByUidR(long uidR)
			throws DatabaseException {
		return commentDao.selectCommentsByUidR(uidR);
	}

	public void createCommentOnUser(Comment comment) throws Exception {
		if (comment != null) {
			if (!RegexUtil.isNullOrEmpty(comment.getComment()))
				commentDao.insertCommentOnUser(comment);
			else
				throw new Exception("Comment cannot be empty");
		} else
			throw new Exception("Comment is null");
	}

	public void createCommentOnMovie(Comment comment) throws Exception {
		if (comment != null) {
			if (!RegexUtil.isNullOrEmpty(comment.getComment()))
				commentDao.insertCommentOnMovie(comment);
			else
				throw new Exception("Comment cannot be empty");
		} else
			throw new Exception("Comment is null");
	}

	public void deleteComment(Comment comment) throws DatabaseException {
		if (comment != null) {
			commentDao.deleteComment(comment);
		}
	}

	public void updateComment(Comment comment) throws DatabaseException {
		if (comment != null) {
			commentDao.updateComment(comment);
		}
	}

	public void incrementCommentFlag(Comment comment) throws DatabaseException {
		if (comment != null) {
			commentDao.incrementCommentFlag(comment);
		}
	}
}
